<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="rgba(255, 255, 255, 0)"
      text-color="#ffffff"
      active-text-color="#20a0ff"
      router
    >
      <template v-for="item in items">
        <template>
          <el-menu-item class="menu-item" :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            {{ item.title }}
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from "../assets/js/bus";
export default {
  data() {
    return {
      collapse: false,
      items: [
        {
          icon: "el-icon-s-home",
          index: "Info",
          title: "系统首页"
        },
        {
          icon: "el-icon-user-solid",
          index: "Consumer",
          title: "用户管理"
        },
        {
          icon: "el-icon-s-order",
          index: "Singer",
          title: "歌手管理"
        },
        {
          icon: "el-icon-menu",
          index: "SongList",
          title: "歌单管理"
        }
      ]
    };
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace("/", "");
    }
  },
  created() {
    // 通过Bus进行组件间的通信，来折叠侧边栏
    bus.$on("collapse", msg => {
      this.collapse = msg;
    });
  }
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  background: #16bffd; /* fallback for old browsers */
  background: -webkit-linear-gradient(
    to bottom,
    #cb3066,
    #16bffd
  ); /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(
    to bottom,
    #cb3066,
    #16bffd
  ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.el-menu-item:hover {
  background-color: rgb(26, 97, 135) !important;
}

.sidebar-el-menu {
  font-weight: bold;
  line-height: 1px;
  letter-spacing: 1px;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 150px;
}

.sidebar > ul {
  height: 100%;
}
</style>
